#include "CommandBuffer.h"

void CommandBuffer::init()
{
}

void CommandBuffer::add_text( char *text )
{
	int l;

	l = strlen( text );
	if ( cmd_text.cursize + l >= cmd_text.maxsize )
	{
		printf( "CommandBuffer::add_text: overflow\n");
		return;
	}
	System::write( &cmd_text, text, strlen( text ) );
}

void CommandBuffer::insert_text( char *text )
{
	char *temp;

	// copy off any commands still remaining in the exec buffer
	if ( cursize )
	{
		temp = Memory::malloc(cursize);
		memcpy( temp, data, cursize );
	}
	else
		temp = NULL;

	// add the entire text of the file
	add_text( text );

	// add the copied off data
	if ( cursize )
	{
		System::write( &cmd_text, temp, cursize );
		Memory::free( temp );
	}
}

void CommandBuffer::copy_to_defer( void )
{
	memcpy( defer_text_buf, cmd_text_buf, cursize );
	defer_text_buf[cursize] = 0;
	cursize = 0;
}

